import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import {resolve} from "node:path";
import vueJsx from '@vitejs/plugin-vue-jsx';
import UnoCSS from 'unocss/vite'

function pathResolve(dir: string) {
  return resolve(process.cwd(), '.', dir)
}

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue(), UnoCSS(), vueJsx()],
  server: {
    port: 80,
    host: true,
    open: true,
    proxy: {
      '/dev-api': {
        target: 'https://mp-test.yongnengyun.cn',
        changeOrigin: true,
        rewrite: (p) => p.replace(/^\/dev-api/, '')
      }
    }
  },
  css: {
    preprocessorOptions: {
      less: {
        modifyVars: {
          // 配置我们定义的less样式变量
          hack: `true; @import (reference) "${path.resolve('src/design/config.less')}";`
        },
        javascriptEnabled: true,
      }
    }
  },
  resolve: {
    /*alias: [
      {
        find: /\@\//,
        replacement: `${pathResolve('src')}/`,
      },
    ],*/
    alias: {
      '@': path.resolve(__dirname, './src')
    }
  },
})
